import getApi from "@/api/getApi"
// 根据存储名读取浏览器cookies中的本地缓存
const getCookie = (cname) => {
    // 参数为存储名
    var name = cname + "=";
    var ca = document.cookie.split(";");
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0)
            return decodeURIComponent(c.substring(name.length, c.length));
    }
    return "";
};
const home = {
    state: {
        userImage: "",
        userName:""
    },
    getters: {
    },
    mutations: {
        getUrl(state) {
            let headerobj = {
                Authorization: getCookie('token')
            }
            getApi('/user/getImage', 'post', {}, headerobj).then((res) => {
                state.userImage = res.data.data
            })
        },
        getName(state){
            let headerobj = {
                Authorization: getCookie('token')
            }
            getApi('/user/getById', 'post', {}, headerobj).then((res) => {
                state.userName = res.data.data.name
            })
        }
    },
    actions: {
        getUrl(context) {
            context.commit('getUrl')
        },
        getName(context){
            context.commit('getName')
        }
    },
    modules: {

    }
}

export default home